package com.spacecolony.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.spacecolony.service.GameServiceStub;
import com.spacecolony.service.IGameService;

/**
 * The activity that represents the menu screen
 * @author Jared
 *
 */
public class MenuActivity extends Activity {

	// add a text view that will hold username and display it on menu layout
	private TextView txtUsername;
	IGameService gameService;

	/**
	 * Creates the activity
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		gameService = new GameServiceStub(this);

		// set the username TextView on the layout to display username
		txtUsername = (TextView) findViewById(R.id.txtUsername);
		txtUsername.setText(getUsername());
	}

	/**
	 * creates the options menu
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.space_colony, menu);
		return true;
	}

	/**
	 * Method launched when start game button is clicked
	 * @param v - view that is clicked
	 */
	public void onStartGameClicked(View v) {

		// create a new intent that tells us to go to GameActivity class.
		Intent gameIntent = new Intent(this, GameActivity.class);

		// start that activity.
		startActivity(gameIntent);
	}

	/** get username from service layer
	 * 
	 * @return - the username of the user
	 */
	public String getUsername() {
		return gameService.getUser().getUsername();

	}

}
